//
//  RankingCell.m
//  TrainTree
//  排行cell
//  Created by wanghui on 2017/9/10.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "RankingCell.h"
@interface RankingCell()
/**第一名数据*/
@property (weak, nonatomic) IBOutlet UILabel *oneName;
@property (weak, nonatomic) IBOutlet UILabel *oneTime;
@property (weak, nonatomic) IBOutlet UILabel *oneClass;
@property (weak, nonatomic) IBOutlet UILabel *oneCommit;
/**第二名数据*/
@property (weak, nonatomic) IBOutlet UIButton *twoRanking;
@property (weak, nonatomic) IBOutlet UILabel *twoName;
@property (weak, nonatomic) IBOutlet UILabel *twoTime;
@property (weak, nonatomic) IBOutlet UILabel *twoClass;
@property (weak, nonatomic) IBOutlet UILabel *twoCommit;
/**第三名数据*/
@property (weak, nonatomic) IBOutlet UIButton *threeRanking;
@property (weak, nonatomic) IBOutlet UILabel *threeName;
@property (weak, nonatomic) IBOutlet UILabel *threeTime;
@property (weak, nonatomic) IBOutlet UILabel *threeClass;
@property (weak, nonatomic) IBOutlet UILabel *threeCommit;
/**我的数据*/
@property (weak, nonatomic) IBOutlet UIButton *myRanking;
@property (weak, nonatomic) IBOutlet UILabel *myName;
@property (weak, nonatomic) IBOutlet UILabel *myTime;
@property (weak, nonatomic) IBOutlet UILabel *myClass;
@property (weak, nonatomic) IBOutlet UILabel *myCommit;
@property (weak, nonatomic) IBOutlet UIView *myView;

@end

@implementation RankingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)configWithArray:(NSArray *)array
{
    if(array.count == 1){
        NSDictionary *dicOne = array[0];
        self.oneName.text = dicOne[@"userName"];
        self.oneTime.text = [NSString stringWithFormat:@"%@", dicOne[@"studyTimeCount"]];
        self.oneClass.text = [NSString stringWithFormat:@"%@", dicOne[@"lessonCount"]];
        self.oneCommit.text = [NSString stringWithFormat:@"%@",dicOne[@"feedbackCount"]];

        self.twoRanking.hidden = YES;
        self.twoName.hidden = YES;
        self.twoTime.hidden = YES;
        self.twoClass.hidden = YES;
        self.twoCommit.hidden = YES;

        self.twoRanking.hidden = YES;
        self.threeName.hidden = YES;
        self.threeTime.hidden = YES;
        self.threeClass.hidden = YES;
        self.threeCommit.hidden = YES;

        self.myView.hidden = YES;
        self.myRanking.hidden = YES;
        self.myName.hidden = YES;
        self.myTime.hidden = YES;
        self.myClass.hidden = YES;
        self.myCommit.hidden = YES;

    }else if (array.count == 2) {
        NSDictionary *dicOne = [[NSDictionary alloc]init];
        NSDictionary *dicTwo = [[NSDictionary alloc]init];
        for (NSDictionary *dic in array) {
            if ([dic[@"position"] intValue] == 1) {
                dicOne = dic;
            }else{
                dicTwo = dic;
            }
        }

        self.oneName.text = [NSString stringWithFormat:@"%@",dicOne[@"userName"]];
        self.oneTime.text = [NSString stringWithFormat:@"%@",dicOne[@"studyTimeCount"]];
        self.oneClass.text = [NSString stringWithFormat:@"%@",dicOne[@"lessonCount"]];
        self.oneCommit.text = [NSString stringWithFormat:@"%@",dicOne[@"feedbackCount"]];

        self.twoRanking.hidden = NO;
        self.twoName.text = [NSString stringWithFormat:@"%@",dicTwo[@"userName"]];
        self.twoTime.text = [NSString stringWithFormat:@"%@",dicTwo[@"studyTimeCount"]];
        self.twoClass.text = [NSString stringWithFormat:@"%@",dicTwo[@"lessonCount"]];
        self.twoCommit.text = [NSString stringWithFormat:@"%@",dicTwo[@"feedbackCount"]];

        self.threeRanking.hidden = YES;
        self.threeName.hidden = YES;
        self.threeTime.hidden = YES;
        self.threeClass.hidden = YES;
        self.threeCommit.hidden = YES;

        self.myView.hidden = YES;
        self.myRanking.hidden = YES;
        self.myName.hidden = YES;
        self.myTime.hidden = YES;
        self.myClass.hidden = YES;
        self.myCommit.hidden = YES;


    } else if (array.count == 3) {
        NSDictionary *dicOne = [[NSDictionary alloc]init];
        NSDictionary *dicTwo = [[NSDictionary alloc]init];
        NSDictionary *dicThree = [[NSDictionary alloc]init];
        for (NSDictionary *dic in array) {
            if ([dic[@"position"] intValue] == 1) {
                dicOne = dic;
            }else if([dic[@"position"] intValue] ==2){
                dicTwo = dic;
            }else{
                dicThree = dic;
            }
        }

        self.oneName.text = [NSString stringWithFormat:@"%@",dicOne[@"userName"]];
        self.oneTime.text = [NSString stringWithFormat:@"%@",dicOne[@"studyTimeCount"]];
        self.oneClass.text = [NSString stringWithFormat:@"%@",dicOne[@"lessonCount"]];
        self.oneCommit.text = [NSString stringWithFormat:@"%@",dicOne[@"feedbackCount"]];

        self.twoRanking.hidden = NO;
        self.twoName.text = [NSString stringWithFormat:@"%@",dicTwo[@"userName"]];
        self.twoTime.text = [NSString stringWithFormat:@"%@",dicTwo[@"studyTimeCount"]];
        self.twoClass.text = [NSString stringWithFormat:@"%@",dicTwo[@"lessonCount"]];
        self.twoCommit.text = [NSString stringWithFormat:@"%@",dicTwo[@"feedbackCount"]];

        self.threeRanking.hidden = NO;
        self.threeName.text = [NSString stringWithFormat:@"%@",dicThree[@"userName"]];
        self.threeTime.text = [NSString stringWithFormat:@"%@",dicThree[@"studyTimeCount"]];
        self.threeClass.text = [NSString stringWithFormat:@"%@",dicThree[@"lessonCount"]];
        self.threeCommit.text = [NSString stringWithFormat:@"%@",dicThree[@"feedbackCount"]];

        self.myView.hidden = YES;
        self.myRanking.hidden = YES;
        self.myName.hidden = YES;
        self.myTime.hidden = YES;
        self.myClass.hidden = YES;
        self.myCommit.hidden = YES;

    } else{// 四条数据
        NSDictionary *dicOne = [[NSDictionary alloc]init];
        NSDictionary *dicTwo = [[NSDictionary alloc]init];
        NSDictionary *dicThree = [[NSDictionary alloc]init];
        NSDictionary *dicMy = [[NSDictionary alloc]init];
        for (NSDictionary *dic in array) {
            if ([dic[@"position"] intValue] == 1) {
                dicOne = dic;
            }else if([dic[@"position"] intValue] == 2){
                dicTwo = dic;
            }else if([dic[@"position"] intValue] == 3) {
                dicThree = dic;
            }else{
                dicMy = dic;
            }
        }

        self.oneName.text = [NSString stringWithFormat:@"%@",dicOne[@"userName"]];
        self.oneTime.text = [NSString stringWithFormat:@"%@",dicOne[@"studyTimeCount"]];
        self.oneClass.text = [NSString stringWithFormat:@"%@",dicOne[@"lessonCount"]];
        self.oneCommit.text = [NSString stringWithFormat:@"%@",dicOne[@"feedbackCount"]];

        self.twoName.text = [NSString stringWithFormat:@"%@",dicTwo[@"userName"]];
        self.twoTime.text = [NSString stringWithFormat:@"%@",dicTwo[@"studyTimeCount"]];
        self.twoClass.text = [NSString stringWithFormat:@"%@",dicTwo[@"lessonCount"]];
        self.twoCommit.text = [NSString stringWithFormat:@"%@",dicTwo[@"feedbackCount"]];

        self.threeName.text = [NSString stringWithFormat:@"%@",dicThree[@"powerCount"]];
        self.threeTime.text = [NSString stringWithFormat:@"%@",dicThree[@"studyTimeCount"]];
        self.threeClass.text = [NSString stringWithFormat:@"%@",dicThree[@"lessonCount"]];
        self.threeCommit.text = [NSString stringWithFormat:@"%@",dicThree[@"feedbackCount"]];

        [self.myRanking setTitle: [NSString stringWithFormat:@"%@",dicMy[@"position"]] forState:UIControlStateNormal];
        self.myName.text = @"我";
        self.threeTime.text = [NSString stringWithFormat:@"%@",dicMy[@"studyTimeCount"]];
        self.threeClass.text = [NSString stringWithFormat:@"%@",dicMy[@"lessonCount"]];
        self.threeCommit.text = [NSString stringWithFormat:@"%@",dicMy[@"feedbackCount"]];

    }

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
